package com.yl.pattern.behavioralmodel.responsibility;

/**
 * @Author 小羊
 * @Date 31/10/2024下午 4:57
 * @ClassName Handler
 * @Description 抽象处理者类
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    private int numStart;
    private int numEnd;

    private Handler nextHandler;

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    /**
     * 设置上级领导对象
     * @param nextHandler
     */
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 处理请假条的方法
     * @param leave
     */
    protected abstract void handlerLevel(LeaveRequest leave);

    public final void submit(LeaveRequest leave) {
        //该领导进行审批
        this.handlerLevel(leave);
        if(this.nextHandler!=null&&leave.getNum()>this.numEnd){
            //提交给上级领导
            this.nextHandler.submit(leave);
        }else {
            System.out.println("流程结束");
        }

    }
}
